#ifndef IPSOCKET_H
#define IPSOCKET_H

#include <QDialog>
#include <QtNetwork/QUdpSocket>
#include <QtNetwork/QTcpSocket>
#include <QtNetwork/QTcpServer>
#include <QMessageBox>
#include <iostream>
using namespace std;

//.pro: QT += network
namespace Ui {
class ipSocket;
}

class ipSocket : public QDialog
{
    Q_OBJECT

public:
    explicit ipSocket(QWidget *parent = 0);
    ~ipSocket();
    bool getStatus(){return isValic;}
    typedef enum{TCPServer,TCPClient,UDPServer,UDPClient}SOCKETTYPE;

private:
    Ui::ipSocket *ui;
    bool isValic;
    SOCKETTYPE type;
    QUdpSocket *udpSocket;
    QTcpSocket *tcpSocket;
    QTcpServer *tcpServer;
    QHostAddress ipAddr;
    quint16 ipSrcPort,ipDetPort;
    QByteArray dataRx,dataTx;

signals:
    void ReadyRecv(QByteArray &data);

private slots:
    void RecvPackets(void);
    void SendPackets(void);
    void SendPackets(QByteArray &data);
    void ConfigSocket(void);
    void NewConnect(void);
    void DisConnect(void);
    void typeChange(void);
};

#endif // IPSOCKET_H
